// miniprogram/pages/bmrs/bmrs.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    page: 195
  },
  //点击选择-省份地市
  choisedishi() {
    var that = this;
    that.setData({
      bindpro: 1,
    })
  },
  //一级联动-省份
  dishi() {
    var that = this;
    wx.request({ //发送请求
      url: 'https://zg99.offcn.com/index/chaxun/getlevel?actid=48234&callback=?', //接收url
      data: {
        level: '1',
        dishi: ''
      }, //接收参数
      success(res) { //返回
        var jsonStr = res.data;
        jsonStr = jsonStr.replace("(", "");
        jsonStr = jsonStr.replace(")", "");
        if (typeof jsonStr != 'object') {
          jsonStr = jsonStr.replace(/\ufeff/g, ""); //字符串转化JSON对象
          var theJson = JSON.parse(jsonStr);
        }
        //console.log(theJson)
        var list = [];
        for (var i in theJson.lists) { //循环写入下来框
          list.push(theJson.lists[i].dishi)
        }
        // console.log(list)
        that.setData({
          dishiList: list
        });
      }
    })
  },
  //点击选择-省份
  setdishi(e) {
    var that = this;
    console.log(e.currentTarget.dataset.dishi)
    that.setData({
      dishi: e.currentTarget.dataset.dishi
    })
    that.xianqu()
  },
  //点击重新选择-省份
  rechoisedishi() {
    var that = this;
    that.setData({
      xianquList: !1,
      xianqu: !1
    })
  },
  //二级联动-地市
  xianqu() {
    var that = this;
    wx.request({ //发送请求
      url: 'https://zg99.offcn.com/index/chaxun/getlevel?actid=48234&callback=?', //接收url
      data: {
        level: '2',
        grfiled: 'dishi',
        grtext: that.data.dishi
      }, //接收参数
      success(res) { //返回
        var jsonStr = res.data;
        jsonStr = jsonStr.replace("(", "");
        jsonStr = jsonStr.replace(")", "");
        if (typeof jsonStr != 'object') {
          jsonStr = jsonStr.replace(/\ufeff/g, ""); //字符串转化JSON对象
          var theJson = JSON.parse(jsonStr);
        }
        // console.log(theJson)
        var list = [];
        for (var i in theJson.lists) { //循环写入下来框
          list.push(theJson.lists[i].xianqu)
        }
        console.log(list)
        that.setData({
          xianquList: list
        });
      }
    })
  },
  //点击选择-地市
  setxianqu(e) {
    var that = this;
    console.log(e.currentTarget.dataset.xianqu)
    that.setData({
      xianqu: e.currentTarget.dataset.xianqu,
      xianquList: !1,
      bindpro: !1
    })
  },

  closeselect() {
    var that = this;
    that.setData({
      bindpro: !1
    })
  },
  //个人信息查询提交
  submit() {
    var that = this;
    var phone = wx.getStorageSync('fsxphone')

      if (that.data.xianqu) {
        wx.request({ //发送请求
          url: 'https://zg99.offcn.com/index/chaxun/getlist?actid=48234&callback=?', //接收url
          data: {
            phone: phone,
            limits: 500,
            dishi: that.data.dishi,
            xianqu: that.data.xianqu
          }, //接收参数
          success(res) { //返回
            var jsonStr = res.data;
            jsonStr = jsonStr.replace("(", "");
            jsonStr = jsonStr.replace(")", "");
            if (typeof jsonStr != 'object') {
              jsonStr = jsonStr.replace(/\ufeff/g, ""); //字符串转化JSON对象
              var theJson = JSON.parse(jsonStr);
            }
            console.log(theJson)
            that.setData({
              lists: theJson.lists
            })
            wx.pageScrollTo({
              scrollTop: 300,
              duration: 600
            });

          }
        })
      } else {
        wx.showToast({
          title: '请完整填写信息',
          duration: 2000,
          icon: 'none'
        })
      }


  },
 

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    console.log(options);
    that.setData({
      area: options.area,
      agent: options.agent
    })
    if (options.page) {
      that.setData({
        page: options.page
      })
    }
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})